package org.dallasrowing.logbook.util;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Date;

public class FormatUtil {
	
	private static DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT , DateFormat.SHORT);
	private static NumberFormat numberFormat;
	
	static {
		numberFormat = NumberFormat.getNumberInstance();
		numberFormat.setMinimumFractionDigits(1);
		numberFormat.setMaximumFractionDigits(1);
	}
	
	public static String formatDate(Date date)
	{
		if (date == null)
			return "";
		
		return dateFormat.format(date);
	}
	
	public static Date parseDate(String dateString) throws ParseException
	{
		return dateFormat.parse(dateString);
	}
	
	public static String formatMiles(Double miles)
	{
		if (miles == null)
			return "";
		return numberFormat.format(miles);
	}

}
